#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <qdebug.h>
#include <qmath.h>
#include <QDateTime>
#include <QMessageBox>
#include <recorddialog.h>
#include <recorddata.h>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    QSerialPort *mySerialPort;                      //定义串口
    int portFlag;
    //收集的数据
    QByteArray leftData;

    RecordDialog *recordDialog;

    struct RecordDataStruct
    {
        double accumTraffic;
        double instantTraffic;
        double accumTime;
        double singleTraffic;
    }myRecordData;

    unsigned char CRC[2];//定义CRC校验输出结果数组


private slots:
    void setSerialPortSlot();
    void findSerialPort();
    void confirmToSet();
    void cancelToSet();
    void setComNum();

    //处理数据
    void processPendingDatagram();
    //分析数据
    void datagramAnalyze(unsigned char tempData[]);

    //CRC16 modbus校验
    uint N_CRC16(uchar *updata,uint len);
    void on_actionHelp_triggered();

    void on_actionVersion_triggered();

    void on_pushButton_RecordTime_clicked();

signals:
    void serialPortSignal(QSerialPort *dialogSerialPort,bool openSerialPort);
    void RecordDataSignal(RecordDataStruct data);
public slots:
    //设置按钮是否可选取
    void setButtonEnable(bool flag);
};

#endif // MAINWINDOW_H
